
//
//  HOPTopView.swift
//  WB01
//
//  Created by HOP on 15/12/20.
//  Copyright © 2015年 HOP. All rights reserved.
//

import UIKit

import SDWebImage

class HOPTopView: UIView {
// 顶部视图显示内容需要模型
    var status: HOPStatus? {
        didSet {
        // 当cell给顶部视图设置模型时,顶部视图根据模型来显示数据
        // 1.显示头像
            if let profile_image_url = status?.user?.profile_image_url {
            let url = NSURL(string: profile_image_url)
            iconView.sd_setImageWithURL(url, placeholderImage: UIImage(named: "avatar"))
            }
            // 2.用户名称
            // nameLabel.text 是一个选
            nameLabel.text = status?.user?.screen_name
            timeLabel.text = "刚刚"
            sourceLabel.text = "火星"
             // 根据不同的等级显示不同的图片
            vipView.image = status?.user?.mbrankImage
            verfiedView.image = status?.user?.verfiedImage
            }
      }
    override init(frame: CGRect) {
        super.init(frame: frame)
        prepareUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func prepareUI() {
    // 1.添加子控件
        addSubview(separatorView)
        addSubview(iconView)
        addSubview(nameLabel)
        addSubview(timeLabel)
        addSubview(sourceLabel)
        addSubview(vipView)
        addSubview(verfiedView)
        // 2.添加约束
        separatorView.ff_AlignInner(type: ff_AlignType.TopLeft, referView: self, size: CGSize(width: UIScreen.mainScreen().bounds.width, height: 10))
          // 头像
        iconView.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: separatorView, size: CGSize(width: 35, height: 35), offset: CGPoint(x: 8, y: 8))
        // 名称
        nameLabel.ff_AlignHorizontal(type: ff_AlignType.TopRight, referView: iconView, size: nil, offset: CGPoint(x: 8, y: 0))
        // 时间
        timeLabel.ff_AlignHorizontal(type: ff_AlignType.BottomRight, referView: iconView, size: nil, offset: CGPoint(x: 8, y: 0))
        // 来源
        sourceLabel.ff_AlignHorizontal(type: ff_AlignType.CenterRight, referView: timeLabel, size: nil, offset: CGPoint(x: 8, y: 0))
    // 会员等级
        vipView.ff_AlignHorizontal(type: ff_AlignType.CenterRight, referView: nameLabel, size: CGSize(width: 14, height: 14), offset: CGPoint(x: 8, y: 0))
        // 认证图标
        verfiedView.ff_AlignInner(type: ff_AlignType.BottomRight, referView: iconView, size: CGSize(width: 17, height: 17), offset: CGPoint(x: 8.5, y: 8.5))
    }
    
    // MARK: - 懒加载
    /// cell的分割视图
    private lazy var separatorView: UIView = {
    let view = UIView()
    // 设置背景
    view.backgroundColor = UIColor(white: 0.95, alpha: 1)
    
    
    return view
    }()
    /// 用户头像
    private lazy var iconView: UIImageView = UIImageView(image: UIImage(named: "avatar"))
    /// 用户名称
    private lazy var nameLabel: UILabel = {
    let label = UILabel()
        label.textColor = UIColor.darkGrayColor()
    label.font = UIFont.systemFontOfSize(14)
        return label
     }()
    /// 微博时间
    private lazy var timeLabel: UILabel = {
    let label = UILabel()
        label.textColor = UIColor.orangeColor()
        label.font = UIFont.systemFontOfSize(9)
    return label
    
    }()
     /// 微博来源
    private lazy var sourceLabel: UILabel = {
    let label = UILabel()
      label.textColor = UIColor.lightGrayColor()
        label.font = UIFont.systemFontOfSize(9)
    return label
    }()
    /// 会员等级
    private lazy var vipView: UIImageView = UIImageView(image: UIImage(named: "common_icon_membership_expired"))
    /// 认证图标
    private lazy var verfiedView: UIImageView = UIImageView(image: nil)
    
 }
